package com.example.mycomposelearing.dataobserval

import android.os.Parcelable
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.rememberSaveable
import kotlinx.parcelize.Parcelize

/**
 *@Author tgw
 *@Date 2023/08/14
 *@describe
 */
data class StateManage(val state: MutableState<Int>)


@Parcelize
 class StateManage1 constructor(var state: Int): Parcelable{
     companion object {
         /**
          * The default [Saver] implementation for [LazyListState].
          */
         val Saver: Saver<StateManage1, Any> =Saver(
             save = { it.state },
             restore = {
                 StateManage1(
                    state = it as Int
                 )
             }
         )
     }


 }

@Composable
fun rememberStateManage(state: MutableState<Int> = mutableStateOf(0))= remember {
    StateManage(state)
}


@Composable
fun rememberSaveableStateManage(state: MutableState<StateManage1> = mutableStateOf(StateManage1(0))) = rememberSaveable {
    state
}